package com.aop.bean;

import org.springframework.aop.framework.AopContext;
import org.springframework.beans.factory.annotation.Autowired;

public class CalculateImpl implements Calculate {

	@Autowired
	private Depend depend;

	public int useDepend(int a, int b) {
		return depend.dependAdd(a, b);
	}

	@Override
	public int add(int a, int b) {
		System.out.println("执行目标方法: add");
//		System.out.println(10 / 0);
		return a + b;
	}

	@Override
	public int subtract(int a, int b) {
		System.out.println("执行目标方法: subtract");
		return a - b;
	}

	@Override
	public int multiply(int a, int b) {
		System.out.println("执行目标方法: multiply");
		return a * b;
	}

	@Override
	public int divide(int a, int b) {
		System.out.println("执行目标方法: divide");
		return a / b;
	}

	@Override
	public int modulus(int a, int b) {
		System.out.println("执行目标方法: modulus");

//		int result = this.add(a, b);
		int result = ((Calculate) AopContext.currentProxy()).add(a, b);
		return result % a;

//		return a % b;
	}
}
